package com.xjy.web.controller.system;

import java.util.List;
import java.util.Arrays;

import com.xjy.system.domain.SysContractType;
import com.xjy.system.domain.bo.SysContractTypeAddBo;
import com.xjy.system.domain.bo.SysContractTypeEditBo;
import com.xjy.system.domain.bo.SysContractTypeQueryBo;
import com.xjy.system.domain.resp.SysContractTypeResp;
import com.xjy.system.domain.vo.SysContractTypeVo;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.xjy.common.annotation.RepeatSubmit;
import com.xjy.common.annotation.Log;
import com.xjy.common.core.controller.BaseController;
import com.xjy.common.core.domain.AjaxResult;
import com.xjy.common.enums.BusinessType;
import com.xjy.system.service.ISysContractTypeService;
import com.xjy.common.utils.poi.ExcelUtil;
import com.xjy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 合同类型Controller
 *
 * @author xjy
 * @date 2022-02-08
 */
@Api(value = "合同类型控制器", tags = {"合同类型管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/type")
public class SysContractTypeController extends BaseController {

    private final ISysContractTypeService iSysContractTypeService;

    /**
     * 查询合同类型列表
     */
    @ApiOperation("查询合同类型列表")
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public SysContractTypeResp list(@Validated SysContractTypeQueryBo bo) {
        return iSysContractTypeService.queryPageList(bo);
    }

	/**
	 * 查询合同类型列表 根据大类id查询小类
	 */
	@ApiOperation("查询合同类型列表")
	@GetMapping("/listtype")
	public List<SysContractType> listtype(String maxtype) {
		return iSysContractTypeService.queryPageListtype(maxtype);
	}


	@ApiOperation("合同类型列表")
	@PreAuthorize("@ss.hasPermi('system:type:collects')")
	@GetMapping("/collects")
	public TableDataInfo<SysContractTypeVo> collects(@Validated SysContractTypeQueryBo bo) {
		return iSysContractTypeService.collects(bo);
	}

    /**
     * 导出合同类型列表
     */
    @ApiOperation("导出合同类型列表")
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "合同类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<SysContractTypeVo> export(@Validated SysContractTypeQueryBo bo) {
        List<SysContractTypeVo> list = iSysContractTypeService.queryList(bo);
        ExcelUtil<SysContractTypeVo> util = new ExcelUtil<SysContractTypeVo>(SysContractTypeVo.class);
        return util.exportExcel(list, "合同类型");
    }

    /**
     * 获取合同类型详细信息
     */
    @ApiOperation("获取合同类型详细信息")
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping("/{id}")
    public AjaxResult<SysContractTypeVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iSysContractTypeService.queryById(id));
    }

    /**
     * 新增合同类型
     */
    @ApiOperation("新增合同类型")
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "合同类型", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody SysContractTypeAddBo bo) {
        return toAjax(iSysContractTypeService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改合同类型
     */
    @ApiOperation("修改合同类型")
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "合同类型", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody SysContractTypeEditBo bo) {
        return toAjax(iSysContractTypeService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除合同类型
     */
    @ApiOperation("删除合同类型")
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "合同类型" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iSysContractTypeService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

}
